package org.celery.modules.ticket.service.impl;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.ocean.rawsdk.ApiExecutor;
import com.alibaba.ocean.rawsdk.client.APIId;
import com.alibaba.ocean.rawsdk.common.SDKResult;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.AllArgsConstructor;
import org.apache.commons.beanutils.ConvertUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.logging.log4j.util.Strings;
import org.celery.common.config.AlibabaProperties;
import org.celery.modules.productSource.entity.ProductSource;
import org.celery.modules.productSource.service.IProductSourceService;
import org.celery.modules.purchase.entity.Purchase;
import org.celery.modules.purchase.service.IPurchaseService;
import org.celery.modules.shop.entity.Shop;
import org.celery.modules.shop.service.IShopService;
import org.celery.modules.ticket.dto.TicketDTO;
import org.celery.modules.ticket.entity.*;
import org.celery.modules.ticket.enums.payStatusEnum;
import org.celery.modules.ticket.enums.refundStatusEnum;
import org.celery.modules.ticket.enums.transactionStatusEnum;
import org.celery.modules.ticket.vo.TicketVO;
import org.celery.modules.ticket.mapper.TicketMapper;
import org.celery.modules.ticket.service.ITicketService;
import org.springblade.core.log.exception.ServiceException;
import org.springblade.core.mp.base.BaseServiceImpl;
import org.springblade.core.mp.support.Condition;
import org.springblade.core.mp.support.Query;
import org.springblade.core.secure.BladeUser;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.constant.BladeConstant;
import org.springblade.core.tool.utils.Func;
import org.springblade.core.tool.utils.Lazy;
import org.springblade.core.tool.utils.SpringUtil;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.core.metadata.IPage;

import java.math.BigDecimal;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.stream.Collectors;

/**
 * 订单表 服务实现类
 *
 * @author Celery
 * @since 2023-06-12
 */
@Service
@AllArgsConstructor
public class TicketServiceImpl extends BaseServiceImpl<TicketMapper, Ticket> implements ITicketService {

	private final AlibabaProperties alibabaProperties;

	private final IShopService shopService;

	private final Lazy<IProductSourceService> productSourceService = Lazy.of(
			() -> SpringUtil.getBean(IProductSourceService.class));

	private final TicketMapper mapper;

	private static Long shopIdStatic = 1670753159815319553L;

	@Override
	public IPage<TicketVO> selectTicketPage(IPage<TicketVO> page, TicketVO ticket) {
		return page.setRecords(baseMapper.selectTicketPage(page, ticket));
	}

	@Override
	public IPage<Ticket> getOrderList(Ticket order, Query query) {
		return page(Condition.getPage(query), Condition.getQueryWrapper(order).lambda().orderByDesc(Ticket::getTradingHours));
	}

	@Override
	public Boolean deleteOrder(Long orderId) {
		return update(Wrappers.<Ticket>lambdaUpdate().set(Ticket::getIsDeleted, 1).eq(Ticket::getId, orderId));
	}

	@Override
	public Boolean modifyOrder(Ticket order) {
		if(Func.isEmpty(order.getId())) {
			throw new ServiceException("请传入id");
		}
		return updateById(order);
	}

	@Override
	public Boolean addOrder(Ticket order) {
		return save(order);
	}
	@Override
	public Boolean addOrderInput(List<TicketDTO> orders) {
		ArrayList<Ticket> tickets = new ArrayList<>();
		for (TicketDTO order : orders) {
			Ticket ticket = initOrderEntity(order);
			tickets.add(ticket);
		}
		return saveOrUpdateBatch(tickets);
	}

	//最后一个字符替换
	public static String replaceLast(String text, String strToReplace, String replaceWithThis) {
		return text.replaceFirst("(?s)" + strToReplace + "(?!.*?" + strToReplace + ")", replaceWithThis);
	}

	public Ticket initOrderEntity(TicketDTO order) {
		String timeStr = "";
		String officialLogisticOrder;
		Object productItemsList;
		Object tradeTermsList;
//		String extAttributes = JSON.toJSONString(order.getExtAttributes());
		String nativeLogistics = JSON.toJSONString(order.getNativeLogistics());
		officialLogisticOrder = order.getOfficialLogisticOrder().toString();
		String orderRateInfo = JSON.toJSONString(order.getOrderRateInfo());
		String productItems = JSON.toJSONString(order.getProductItems());
		String tradeTerms = JSON.toJSONString(order.getTradeTerms());
		Ticket ticket = new Ticket();
//		ticket.setExtAttributes(extAttributes);
		ticket.setNativeLogistics(nativeLogistics);
		ticket.setOfficialLogisticOrder(officialLogisticOrder);
		ticket.setOrderRateInfo(orderRateInfo);
		ticket.setProductItems(productItems);
		ticket.setTradeTerms(tradeTerms);
		// 目前考虑只有一个的情况
		if(order.getProductItems().size() > 0 && order.getTradeTerms().size() > 0) {
			productItemsList = (order.getProductItems()).get(0);
			tradeTermsList = (order.getTradeTerms()).get(0);
			HashMap baseInfo = (HashMap) order.getBaseInfo();
			HashMap nativeLogisticObj = (HashMap) order.getNativeLogistics();
			Object buyerContact = baseInfo.get("buyerContact");
			// 商品明细条目id，如有多个以,分隔
			ticket.setId(Long.valueOf(((HashMap) productItemsList).get("subItemID").toString()));
			// buyerID 买家主账号id
			ticket.setUserId(baseInfo.get("subItemID") == null ? null : Long.valueOf(baseInfo.get("subItemID").toString()));
			// 买家name
			Object sellerContact = baseInfo.get("sellerContact");
			ticket.setUserName(((HashMap) sellerContact).get("companyName").toString());
			// gmtCreate创建时间
			ticket.setTradingHours(LocalDateTime.parse(((HashMap) productItemsList).get("gmtCreate").toString(), DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
			// 间隔时间自己计算（）20230502205543000+0800
			// 更新时间((HashMap)productItemsList).get("gmtCreate").toString().substring(0, 14)
			// 商品名称
			ticket.setTradeName(((HashMap) productItemsList).get("name").toString().replaceAll("。", ""));
			// 物品规格
			ArrayList skuInfos = customStringTransArray(((HashMap) productItemsList).get("skuInfos").toString(), true);
			ticket.setSpecifications(JSON.toJSONString(skuInfos));
			// 交易状态
			ticket.setStepStatus(((HashMap) productItemsList).get("status").toString());
			// 交易状态字符串
			ticket.setStepStatusStr(((HashMap) productItemsList).get("statusStr").toString());
			// 商品单价
			ticket.setCommodityUnivalent(new BigDecimal(((HashMap) productItemsList).get("price").toString()));
			// 商品数量
			ticket.setCommodityNum(Integer.valueOf(((HashMap) productItemsList).get("quantity").toString()));
			// 商品实际支付价格
			ticket.setCommodityPrice(new BigDecimal(((HashMap) productItemsList).get("itemAmount").toString()));
			// 商品实际支付价格
			ticket.setActualPrice(new BigDecimal(baseInfo.get("totalAmount").toString()));
			// 商品运费
			ticket.setShippingFee(Integer.valueOf(baseInfo.get("shippingFee").toString()));
			// 订单状态orderStatus,爬取数据没有需要手动
			ticket.setOrderStatus(order.getOrderStatus());
			// 订单整体,爬取数据没有需要手动（）
			// 买家信息
			HashMap infoMap = customStringTransObject(baseInfo.get("sellerContact").toString());
			ticket.setBuyerInfo(JSON.toJSONString(infoMap));
			// 买家具体信息
			HashMap buyerContactInfoMap = customStringTransObject(baseInfo.get("buyerContact").toString());
			ticket.setBuyerContact(JSON.toJSONString(buyerContactInfoMap));
			// 买家地址
			HashMap addMap = customStringTransObject(order.getNativeLogistics().toString());
			ticket.setAddress(JSON.toJSONString(addMap));
			// 留言信息closeOperateType
			ticket.setMessageInfo(baseInfo.get("closeOperateType") == null ? null : baseInfo.get("closeOperateType").toString());
			// 店铺备注remark
			ticket.setStoreNotes(((HashMap) productItemsList).get("remark") == null ? null : ((HashMap) productItemsList).get("remark").toString());
			// 创建人buyerID
			ticket.setCreateUser(baseInfo.get("buyerID") == null ? null : Long.valueOf(baseInfo.get("buyerID").toString()));
			// 创建时间createTime
			timeStr = baseInfo.get("createTime").toString().substring(0, baseInfo.get("createTime").toString().length() - 5);
			try {
				ticket.setCreateTime(new SimpleDateFormat("yyyyMMddHHmmss").parse(timeStr));
			} catch (ParseException e) {
				throw new RuntimeException(e);
			}
			// 更新人
			ticket.setUserId(Long.valueOf(baseInfo.get("id").toString()));
			ticket.setUserId(baseInfo.get("buyerID") == null ? null : Long.valueOf(baseInfo.get("buyerID").toString()));
			timeStr = baseInfo.get("createTime").toString().substring(0, baseInfo.get("createTime").toString().length() - 5);
			try {
				ticket.setUpdateTime(new SimpleDateFormat("yyyyMMddHHmmss").parse(timeStr));
			} catch (ParseException e) {
				throw new RuntimeException(e);
			}
			// 图片链接productImgUrl
			// 处理图片
			String[] productImgUrls = ((HashMap) productItemsList).get("productImgUrl").toString().replace("[", "").replace("]", "").split(",");
			ticket.setImgUrl(JSON.toJSONString(productImgUrls));
			// 退款状态refundStatus
			ticket.setRefundStatus(refundStatusEnum.getName(((HashMap) productItemsList).get("refundStatus").toString()));
			// 商品货号productCargoNumber
			ticket.setProductNumber((((HashMap) productItemsList).get("productCargoNumber") != null) ? ((HashMap) productItemsList).get("productCargoNumber").toString() : null);
			// 交易状态statusStr
			ticket.setIsDeleted(0);
			// 交易平台（这里设置为1688)
			ticket.setTradingPlatform("1688");
			// 联系人在平台的IM账号
			ticket.setSellerImPlatform(((HashMap) sellerContact).get("imInPlatform").toString());
			ticket.setBuyerImPlatform(((HashMap) buyerContact).get("imInPlatform").toString());
			// mobile
			ticket.setMobile(((HashMap) sellerContact).get("mobile") == null ? null : ((HashMap) sellerContact).get("mobile").toString());
			// 店铺备注的id
			ticket.setRefundId(((HashMap) productItemsList).get("refundId").toString());
			// 详细地址
			ticket.setDetailAddress(StringUtils.join(nativeLogisticObj.get("address").toString().split(" "), "/"));
			ticket.setPayStatus(payStatusEnum.getName(Integer.valueOf(((HashMap) tradeTermsList).get("payStatus").toString())));
			// 新增 productId
			ticket.setProductId(Long.valueOf(((HashMap) productItemsList).get("productID").toString()));
			return ticket;
		}
		return null;
	}

	public ArrayList customStringTransArray(String str, Boolean isSubToString) {
		ArrayList<String> list = new ArrayList<>();
		str = str.replaceAll("},", "}-");
		str = str.replaceAll("\\[", "").replaceAll("]", "");
		String[] split = str.split("-");
		for (String s : split) {
			s = s.replaceAll("\\{", "").replaceAll("}", "").trim();
			list.add(s);
		}
		if(isSubToString) {
			return customListToObject(list);
		}
		return list;
	}

	// string转list后再转object子项
	public ArrayList customListToObject(ArrayList<String> list) {
		if(list.size() > 0) {
			ArrayList<Object> hashList = new ArrayList<>();
			for (String str : list) {
				str = str.trim();
				HashMap<String, Object> hashMap = new HashMap<>();
				String[] split = str.split(",");
				if(split.length > 1) {
					for (String s : split) {
						String[] split_sub = s.split("=");
						hashMap.put(split_sub[0].trim(), split_sub[1].trim());
					}
				}
				hashList.add(hashMap);
			}
			return hashList;
		}
		return list;
	}

	// 字符串转为对象格式，自定义
	public HashMap customStringTransObject(String str) {
		HashMap<String, Object> map = new HashMap<>();
		str = str.replace("{", "").replace("}", "");
		String[] split = str.split(",");
		for (String s : split) {
			s = s.trim();
			String[] split1 = s.split("=");
			if(split1.length > 1) {
				map.put(split1[0], split1[1]);
			}
		}
		return map;
	}

	@Override
	public Ticket getOrderById(Long orderId) {
		return getOne(Wrappers.<Ticket>lambdaQuery().eq(Ticket::getId, orderId));
	}

	@Override
	public Boolean batchDeleteOrder(String orderIds) {
		String[] splitOrderIds = orderIds.split(",");
		Long[] OrderIds = (Long[]) ConvertUtils.convert(splitOrderIds, Long.class);
		return removeByIds(Arrays.asList(OrderIds));
	}

	@Override
	public Boolean batchModifyOrder(List<Ticket> orders) {
		return updateBatchById(orders);
	}

	@Override
	public Boolean batchAddOrder(List<Ticket> orders) {
		return saveBatch(orders);
	}

	@Override
	public IPage<Ticket> getOrderLikeId(Ticket order, Query query) {
		return page(Condition.getPage(query),
				Wrappers.<Ticket>lambdaQuery().like(order.getId() != null, Ticket::getId, order.getId()));
	}

	@Override
	public IPage<Ticket> getPayStatusByLike(Integer payStatusValue, Query query) {
		return page(Condition.getPage(query), Wrappers.<Ticket>lambdaQuery().eq(Ticket::getPayStatus, payStatusEnum.getName(payStatusValue)));
	}

	@Override
	public IPage<Ticket> getTransactionStatus(String transactionStatus, Query query) {
		// TODO 临时调整
		if(transactionStatus.equals("terminated")) {
			return page(Condition.getPage(query), Wrappers.<Ticket>lambdaQuery().eq(Ticket::getStepStatus, transactionStatusEnum.getValue(transactionStatus)).or().eq(Ticket::getStepStatus, transactionStatusEnum.getValue("cancel")));
		} else {
			return page(Condition.getPage(query), Wrappers.<Ticket>lambdaQuery().eq(Ticket::getStepStatus, transactionStatusEnum.getValue(transactionStatus)));
		}
	}

	public IPage<Ticket> getRefundStatus(String refundStatus, Query query) {
		return page(Condition.getPage(query), Wrappers.<Ticket>lambdaQuery().eq(Ticket::getRefundStatus, refundStatusEnum.getValue(refundStatus)));
	}

	public IPage<Ticket> getTicketByKeywords(String keys, Query query) {
		// 对每一个字段都用或关联(需要将字段单独抽取出来存储)
		return page(Condition.getPage(query), Wrappers.<Ticket>lambdaQuery().like(Ticket::getId, keys)
				.or().like(Ticket::getUserName, keys)
				.or().like(Ticket::getTradingPlatform, keys)
				.or().like(Ticket::getTradeName, keys)
				.or().like(Ticket::getBuyerInfo, keys));
	}

	public IPage<Ticket> getTicketByCondition(SearchEntity searchEntity, Query query, BladeUser user) {
		QueryWrapper<Ticket> queryWrapper = new QueryWrapper<>();
		if(Func.isNotEmpty(searchEntity.getKeyValue())) {
			queryWrapper.lambda().like(Ticket::getId, searchEntity.getKeyValue())
					.or().like(Ticket::getTradingPlatform, searchEntity.getKeyValue())
					.or().like(Ticket::getUserName, searchEntity.getKeyValue())
					.or().like(Ticket::getTradeName, searchEntity.getKeyValue())
					.or().like(Ticket::getProductNumber, searchEntity.getKeyValue())
					.or().like(Ticket::getBuyerImPlatform, searchEntity.getKeyValue())
					.or().like(Ticket::getSellerImPlatform, searchEntity.getKeyValue())
					.or().like(Ticket::getMobile, searchEntity.getKeyValue())
					.or().like(Ticket::getRefundId, searchEntity.getKeyValue())
					.or().like(Ticket::getRefundStatus, searchEntity.getKeyValue())
					.or().like(Ticket::getSpecifications, searchEntity.getKeyValue())
					.or().like(Ticket::getStepStatusStr, searchEntity.getKeyValue())
					.or().like(Ticket::getCommodityUnivalent, searchEntity.getKeyValue())
					.or().like(Ticket::getCommodityNum, searchEntity.getKeyValue())
					.or().like(Ticket::getActualPrice, searchEntity.getKeyValue())
					.or().like(Ticket::getShippingFee, searchEntity.getKeyValue())
					.or().like(Ticket::getTradingHours, searchEntity.getKeyValue())
					.or().like(Ticket::getPayStatus, searchEntity.getKeyValue());
		}
		if(Func.isNotEmpty(searchEntity.getShopSelect())) {
			Shop shop = shopService.getShopById(Long.valueOf(searchEntity.getShopSelect()));
			queryWrapper.lambda().eq(Ticket::getUserName, shop.getResourceOwner());
		}

		if(!user.getTenantId().equals(BladeConstant.ADMIN_TENANT_ID) || (!user.getRoleName().contains("administrator") && !user.getRoleName().contains("s_admin") && !user.getRoleName().contains("caiwu") && !user.getRoleName().contains("fake_boss"))) {
			List<Shop> shopList = shopService.authList(user);
			if (Func.isEmpty(shopList)) {
				return new Page<>();
			}

			List<String> shopNameList = shopList.stream().map(Shop::getResourceOwner).collect(Collectors.toList());
			queryWrapper.lambda().in(Ticket::getUserName, shopNameList);
		}

		if(Func.isNotEmpty(searchEntity.getProcureSelect())) {
			// 采购实体
		}
		if(Func.isNotEmpty(searchEntity.getStartTime()) && Func.isNotEmpty(searchEntity.getEndTime())) {
			if(searchEntity.getStartTime().isAfter(searchEntity.getEndTime())) {
				throw new ServiceException("时间倒置");
			}
			queryWrapper.lambda().between(Ticket::getCreateTime, searchEntity.getStartTime(), searchEntity.getEndTime());
		}

		if(Func.isNotEmpty(searchEntity.getSlotNumber())) {
			queryWrapper.lambda().eq(Ticket::getId, searchEntity.getSlotNumber());
		}

		if(Func.isNotEmpty(searchEntity.getLowPrice()) && Func.isNotEmpty(searchEntity.getHighPrice())) {
			if(searchEntity.getLowPrice() > searchEntity.getHighPrice()) {
				throw new ServiceException("最低价格不能超过最高价格");
			}
			queryWrapper.lambda().between(Ticket::getCommodityUnivalent, searchEntity.getLowPrice(), searchEntity.getHighPrice());
		}
		return page(Condition.getPage(query), queryWrapper);
	}

	public List<HashMap<String, String>> getShopSelectData() {
		List<HashMap<String, String>> collect = this.list().stream().filter(distinctByKey(item -> item.getTradingPlatform())).collect(Collectors.groupingBy(Ticket::getTradingPlatform))
				.entrySet().stream().map(item -> {
					return new HashMap<String, String>() {{
						put("label", item.getKey());
						put("desc", "店铺");
						put("value", item.getKey());
					}};
				}).collect(Collectors.toList());
		return collect;
	}

	public static <T> Predicate<T> distinctByKey(Function<? super T, ?> keyExtractor) {
		Map<Object,Boolean> seen = new ConcurrentHashMap<>();
		return t -> seen.putIfAbsent(keyExtractor.apply(t), Boolean.TRUE) == null;
	}

	public Object getTradeGetLogisticsInfosSellerViewList(Long orderId, String webSite) {
		ApiExecutor apiExecutor = new ApiExecutor(alibabaProperties.getAppKey(), alibabaProperties.getAppSecret());
		AlibabaTradeEcGetOrderSellerViewParam param = new AlibabaTradeEcGetOrderSellerViewParam();
		param.setOceanApiId(new APIId("com.alibaba.trade", "alibaba.trade.ec.getOrder.sellerView", 1));
		if(Func.isEmpty(orderId)){
			throw new ServiceException("orderId参数必传");
		}
		Shop currentShop = shopService.getShopById(shopIdStatic);
		param.setOrderId(orderId);
		SDKResult<AlibabaTradeEcGetOrderSellerViewResult> result = apiExecutor.execute(param, currentShop.getAccessToken());
		if(result.getResult() != null) {
			return result;
		}
		return false;
	}

	public ArrayList<HashMap<String, String>> getTicketListForBuyerInfo(Long orderId) {
		// 先寻找是否存在添加了商品源基础地址的记录
		List<Ticket> list = list(Wrappers.<Ticket>lambdaQuery().eq(Ticket::getId, orderId).eq(Ticket::getIsDeleted, 0));
		if(list.size() > 1) {
			throw new ServiceException("存在多条记录");
		}
		List<ProductSource> productSourcesList = productSourceService.get().list(Wrappers.<ProductSource>lambdaQuery().eq(ProductSource::getProductId, list.get(0).getProductId()).ne(ProductSource::getBaseUrl, ""));
		if(productSourcesList.size() > 1) {
			throw new ServiceException("存在多条记录");
		}
//		获取对应的数据
		Object tradeGetLogisticsInfosSellerViewList = getTradeGetLogisticsInfosSellerViewList(orderId, "1688");
		if(Func.isEmpty(tradeGetLogisticsInfosSellerViewList)) {
			throw new ServiceException("转化异常");
		}
		Object result1 = ((SDKResult) tradeGetLogisticsInfosSellerViewList).getResult();
		if (Func.isEmpty(result1)) {
			throw new ServiceException("转化异常");
		}
		Object result = ((AlibabaTradeEcGetOrderSellerViewResult) result1).getResult();
		if(Func.isEmpty(result)) {
			throw new ServiceException("转化异常");
		}
		Object nativeLogistics = ((JSONObject) result).get("nativeLogistics");
		if(Func.isEmpty(nativeLogistics)) {
			throw new ServiceException("转化异常");
		}
		ArrayList<HashMap<String, String>> arrayList = new ArrayList<>();
		String province = ((JSONObject) nativeLogistics).get("province").toString();
		String city = ((JSONObject) nativeLogistics).get("city").toString();
		String area = ((JSONObject) nativeLogistics).get("area").toString();
		String town = ((JSONObject) nativeLogistics).get("town").toString();
		String address = ((JSONObject) nativeLogistics).get("address").toString();
		String mobile = ((JSONObject) nativeLogistics).get("mobile").toString();
		String contactPerson = ((JSONObject) nativeLogistics).get("contactPerson").toString();
		if(Func.isEmpty(province) && Func.isEmpty(city) && Func.isEmpty(area) && Func.isEmpty(town) && Func.isEmpty(address)
		&& Func.isEmpty(mobile) && Func.isEmpty(contactPerson)) {
			throw new ServiceException("参数转化错误");
		}
		String addressDeal = Arrays.asList(province, city, area, town, address).stream().collect(Collectors.joining("/"));
		HashMap<String, String> hashMapName = new HashMap<String, String>() {{
			put("title", "买家姓名");
			put("value", contactPerson);
		}};
		HashMap<String, String> hashMapNumber = new HashMap<String, String>() {{
			put("title", "买家电话");
			put("value", mobile);
		}};
		HashMap<String, String> hashMapAddress = new HashMap<String, String>() {{
			put("title", "买家地址");
			put("value", addressDeal);
		}};
		arrayList.add(hashMapName);
		arrayList.add(hashMapNumber);
		arrayList.add(hashMapAddress);
		if(productSourcesList.size() == 1) {
			Ticket ticket = list.get(0);
			ProductSource productSource = productSourcesList.get(0);
			String url = productSource.getBaseUrl() + "?word=" + ticket.getTradeName();
			HashMap<String, String> hashMapAddressUrl = new HashMap<String, String>() {{
				put("addressUrl", "跳转链接");
				put("addressValue", url);
			}};
			arrayList.add(hashMapAddressUrl);
			return arrayList;
		}
		HashMap<String, String> hashMapAddressUrl = new HashMap<String, String>() {{
			put("addressUrl", "跳转链接");
			put("addressValue", "");
		}};
		arrayList.add(hashMapAddressUrl);
		return arrayList;
	}

	@Override
	public Object getLogisticsInfosSellerView(Long orderId, String website) {
		ApiExecutor apiExecutor = new ApiExecutor(alibabaProperties.getAppKey(), alibabaProperties.getAppSecret());
		AlibabaTradeEcGetLogisticsInfosSellerViewParam param = new AlibabaTradeEcGetLogisticsInfosSellerViewParam();
		param.setOceanApiId(new APIId("com.alibaba.trade", "alibaba.trade.ec.getLogisticsInfos.sellerView", 1));
		if(Func.isEmpty(orderId)){
			throw new ServiceException("orderId参数必传");
		}
		if(Func.isEmpty(website)){
			throw new ServiceException("website参数必传");
		}
		Shop currentShop = shopService.getShopById(shopIdStatic);
		param.setOrderId(orderId);
		param.setWebSite(website);
		SDKResult<AlibabaTradeEcGetLogisticsInfosSellerViewResult> result = apiExecutor.execute(param, currentShop.getAccessToken());
		if(result.getResult() != null) {
			return result;
		}
		return null;
	}

	@Override
	public String getSendGoodUrl(Long orderId) {
		IPurchaseService purchaseService = SpringUtil.getBean(IPurchaseService.class);
		Purchase obj = purchaseService.getOne(Wrappers.<Purchase>lambdaQuery().eq(Purchase::getIsDeleted, 0).eq(Purchase::getTicketId, orderId));
		String url = "";
		if(Func.isNotEmpty(obj)) {
			url = "https://mobile.yangkeduo.com/goods_express.html" + "?" + "order_sn" + "=" + obj.getPurchaseCode();
		}
		return url;
	}

	@Override
	public Boolean changeTicketStatus(Long orderId) {
		ITicketService ticketService = SpringUtil.getBean(ITicketService.class);
		Ticket obj = ticketService.getOne(Wrappers.<Ticket>lambdaQuery().eq(Ticket::getIsDeleted, 0).eq(Ticket::getId, orderId));
		obj.setStepStatus("waitbuyerreceive");;
		return ticketService.save(obj);
	}
}
